<template>
  <!-- 菜单项 -->
  <el-aside :width="$store.state.isCollapsed ? '64px' : '200px'">
    <el-menu
      class="el-menu-vertical-demo"
      :collapse="$store.state.isCollapsed"
      :collapse-transition="false"
      :router="true"
      :default-active="router.fullPath"
    >
      <!-- 首页 -->
      <el-menu-item index="/index">
        <el-icon><HomeFilled /></el-icon>
        <span>首页</span>
      </el-menu-item>
      <!-- 个人中心 -->
      <el-menu-item index="/center">
        <el-icon><Avatar /></el-icon>
        <span>个人中心</span>
      </el-menu-item>
      <!-- 用户管理 -->
      <el-sub-menu index="/user-manage" v-admin>
        <template #title>
          <el-icon><UserFilled /></el-icon>
          <span>用户管理</span>
        </template>
        <el-menu-item index="/user-manage/UserAdd">添加用户</el-menu-item>
        <el-menu-item index="/user-manage/UserList">用户列表</el-menu-item>
      </el-sub-menu>
      <!-- 新闻管理 -->
      <el-sub-menu index="/news-manage">
        <template #title>
          <el-icon><MessageBox /></el-icon>
          <span>新闻列表</span>
        </template>
        <el-menu-item index="/news-manage/NewsAdd">添加新闻</el-menu-item>
        <el-menu-item index="/news-manage/NewsList">新闻列表</el-menu-item>
      </el-sub-menu>
      <!-- 产品管理 -->
      <el-sub-menu index="/product-manage">
        <template #title>
          <el-icon><Reading /></el-icon>
          <span>产品管理</span>
        </template>
        <el-menu-item index="/product-manage/ProductAdd">添加产品</el-menu-item>
        <el-menu-item index="/product-manage/ProductList">
          产品列表
        </el-menu-item>
      </el-sub-menu>
      <!-- ... -->
    </el-menu>
  </el-aside>
</template>

<script setup>
import { ref } from "vue";
// 图标
import {
  HomeFilled,
  Avatar,
  UserFilled,
  MessageBox,
  Reading,
  Pointer,
  Expand,
  Fold,
} from "@element-plus/icons-vue";
import { useRoute } from "vue-router";
import { useStore } from "vuex";

const router = useRoute();
const store = useStore();

// 自定义指令-控制侧边栏正确显示对应的用户权限内容
const vAdmin = {
  mounted(el) {
    if (store.state.userInfo.role !== 1) {
      el.parentNode.removeChild(el);
    }
  },
};
</script>

<style lang="scss" scoped>
.el-aside {
  height: 100vh;
  .el-menu {
    height: 100vh;
  }
}
</style>
